package com.example.wuyurun

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity

class AddStudentActivity : AppCompatActivity() {
    private lateinit var etId: EditText
    private lateinit var etName: EditText
    private lateinit var etGender: EditText
    private lateinit var etClass: EditText
    private lateinit var btnSave: Button
    private lateinit var btnCancel: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_add_student)

        etId = findViewById(R.id.et_student_id)
        etName = findViewById(R.id.et_student_name)
        etGender = findViewById(R.id.et_student_gender)
        etClass = findViewById(R.id.et_student_class)
        btnSave = findViewById(R.id.btn_save_student)
        btnCancel = findViewById(R.id.btn_cancel)

        btnSave.setOnClickListener {
            val id = etId.text.toString()
            val name = etName.text.toString()
            val gender = etGender.text.toString()
            val className = etClass.text.toString()
            val intent = Intent()
            intent.putExtra("student", "$id,$name,$gender,$className")
            setResult(RESULT_OK, intent)
            finish()
        }

        btnCancel.setOnClickListener {
            finish()
        }
    }
}